/*
 * Copyright (C) 2008 GeoScheduler Team, as stated on <http://www.geoscheduler.org/authors>.
 * 
 * This file is part of GeoScheduler.
 * 
 * GeoScheduler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GeoScheduler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with GeoScheduler. If not, see <http://www.gnu.org/licenses/>.
 */
package org.geoscheduler.commons.collections;

import java.util.Map;

/**
 * 
 * <h2>MapBuilder</h2>
 * <p>Type safe {@link Map} builder helper. Map is built using  Joshuas Blochs
 * builder pattern variation.</p>
 * @author LKo (Lukas.Kolisko@Geoscheduler.Org)
 */
public class MapBuilder<K, V> {

	private Map<K, V> map;

	public MapBuilder(Map<K, V> map) {
		this.map = map;
	}

	/**
	 * Put new item to {@link Map}.
	 * @param key - key of new {@link Map} item
	 * @param value - value of {@link Map} item
	 * @return {@link MapBuilder} instance
	 */
	public MapBuilder<K, V> append(K key, V value) {
		map.put(key, value);
		return this;
	}

	/**
	 * @return {@link Map} instance
	 */
	public Map<K, V> map() {
		return map;
	}

	/**
	 * Static {@link MapBuilder} factory method.
	 * 
	 * @return new {@link MapBuilder} instance wrapping provided {@param map}.
	 */
	public static <K, V> MapBuilder<K, V> getInstance(Map<K, V> map) {
		return new MapBuilder<K, V>(map);
	}
}